import axios from 'axios';
import { Toast } from 'antd-mobile';

const instance = axios.create({
    timeout: 3000,
})
instance.interceptors.response.use(function (res) {
    if (res.status !== 200) {
        Toast.fail('请求失败，请稍后再试', 2)
    }
    return res
});

export default function request(
    url,
    data,
    method = 'get',
    options
) {
    if (method === 'get') {
        return instance.get(
            url, 
            {
                params: data,
                ...options
            }
        )
    }
    if (method === 'post') {
        return instance.post(
            url,
            {
                data,
                ...options
            }
        ) 
    }
}